#include "stdafx.h"
#include "DataTransManager.h"
#include "il/preprocess_il.h"
#include "Timer.h"

#define DATA_EXTENSION_SHIFT_BIT 3
#define INPUT_BUFFER_WIDTH 512



float fft_filter_2048 [] = {
  0.494568f, 1.065186f, 2.383667f, 3.749695f, 4.903015f, 6.045410f, 7.314270f, 8.588013f, 9.771362f, 10.952332f, 12.203186f, 13.455811f, 14.651123f, 15.845215f, 17.087830f, 18.331360f, 19.532776f, 20.733643f, 21.971436f, 23.209839f, 24.415039f, 25.619812f, 26.854736f, 28.089844f, 29.297546f, 30.505066f, 31.737732f, 32.970581f, 34.180176f, 35.389526f, 36.620605f, 37.851868f, 39.062805f, 40.273621f, 41.503601f, 42.733582f, 43.945618f, 45.157532f, 46.386475f, 47.615601f, 48.828308f, 50.041199f, 51.269287f, 52.497620f, 53.711121f, 54.924683f, 56.152161f, 57.379761f, 58.593872f, 59.808044f, 61.035095f, 62.262146f, 63.476746f, 64.691406f, 65.917847f, 67.144348f, 68.359436f, 69.574646f, 70.800720f, 72.026855f, 73.242188f, 74.457703f, 75.683472f, 76.909241f, 78.124939f, 79.340759f, 80.566223f, 81.791809f, 83.007751f, 84.223877f, 85.449097f, 86.674438f, 87.890625f, 89.106873f, 90.331909f, 91.556946f, 92.773376f, 93.989929f, 95.214722f, 96.439514f, 97.656250f, 98.872986f, 100.097595f, 101.322205f, 102.539063f, 103.755920f, 104.980347f, 106.204773f, 107.421875f, 108.638977f, 109.863159f, 111.087402f, 112.304626f, 113.521881f, 114.745941f, 115.970032f, 117.187378f, 118.404785f, 119.628723f, 120.852753f, 122.070190f, 123.287750f, 124.511566f, 125.735474f, 126.953033f, 128.170715f, 129.394470f, 130.618225f, 131.835907f, 133.053619f, 134.277252f, 135.500854f, 136.718689f, 137.936584f, 139.160065f, 140.383606f, 141.601532f, 142.819458f, 144.042877f, 145.266357f, 146.484375f, 147.702484f, 148.925781f, 150.149078f, 151.367096f, 152.585297f, 153.808533f, 155.031769f, 156.249908f, 157.468109f, 158.691315f, 159.914520f, 161.132690f, 162.351013f, 163.574066f, 164.797302f, 166.015564f, 167.233948f, 168.456940f, 169.680054f, 170.898376f, 172.116821f, 173.339783f, 174.562805f, 175.781219f, 176.999725f, 178.222626f, 179.445526f, 180.664032f, 181.882507f, 183.105438f, 184.328278f, 185.546844f, 186.765411f, 187.988220f, 189.211029f, 190.429596f, 191.648254f, 192.871002f, 194.093719f, 195.312347f, 196.531067f, 197.753784f, 198.976501f, 200.195190f, 201.413879f, 202.636566f, 203.859283f, 205.078003f, 206.296814f, 207.519409f, 208.742065f, 209.960815f, 211.179626f, 212.402222f, 213.624786f, 214.843597f, 216.062500f, 217.285034f, 218.507599f, 219.726410f, 220.945282f, 222.167786f, 223.390350f, 224.609253f, 225.828186f, 227.050659f, 228.273132f, 229.492004f, 230.710999f, 231.933441f, 233.155884f, 234.374847f, 235.593872f, 236.816284f, 238.038696f, 239.257690f, 240.476685f, 241.699097f, 242.921509f, 244.140472f, 245.359497f, 246.581879f, 247.804260f, 249.023254f, 250.242340f, 251.464722f, 252.687042f, 253.906097f, 255.125214f, 256.347534f, 257.569824f, 258.788940f, 260.008057f, 261.230316f, 262.452637f, 263.671783f, 264.890961f, 266.113159f, 267.335419f, 268.554504f, 269.773743f, 270.995911f, 272.218140f, 273.437286f, 274.656464f, 275.878693f, 277.100922f, 278.320068f, 279.539307f, 280.761566f, 281.983734f, 283.202942f, 284.422180f, 285.644379f, 286.866547f, 288.085754f, 289.304993f, 290.527191f, 291.749298f, 292.968567f, 294.187897f, 295.410004f, 296.632111f, 297.851379f, 299.070709f, 300.292755f, 301.514954f, 302.734222f, 303.953583f, 305.175629f, 306.397736f, 307.617004f, 308.836334f, 310.058411f, 311.280457f, 312.499939f, 313.719330f, 314.941345f, 316.163422f, 317.382782f, 318.602142f, 319.824158f, 321.046295f, 322.265594f, 323.485016f, 324.707001f, 325.929016f, 327.148407f, 328.367798f, 329.589813f, 330.811829f, 332.031219f, 333.250671f, 334.472656f, 335.694611f, 336.914032f, 338.133453f, 339.355438f, 340.577423f, 341.796875f, 343.016327f, 344.238220f, 345.460236f, 346.679596f, 347.899078f, 349.121033f, 350.342957f, 351.562439f, 352.781891f, 354.003815f, 355.225739f, 356.445221f, 357.664703f, 358.886688f, 360.108612f, 361.328064f, 362.547607f, 363.769470f, 364.991394f, 366.210846f, 367.430359f, 368.652283f, 369.874146f, 371.093689f, 372.313232f, 373.535095f, 374.757019f, 375.976501f, 377.196045f, 378.417877f, 379.639771f, 380.859283f, 382.078857f, 383.300720f, 384.522583f, 385.742065f, 386.961609f, 388.183472f, 389.405304f, 390.624878f, 391.844452f, 393.066284f, 394.288116f, 395.507690f, 396.727234f, 397.949097f, 399.170959f, 400.390503f, 401.610046f, 402.831848f, 404.053711f, 405.273254f, 406.492859f, 407.714691f, 408.936523f, 410.156097f, 411.375732f, 412.597534f, 413.819336f, 415.038940f, 416.258484f, 417.480347f, 418.702148f, 419.921753f, 421.141357f, 422.363129f, 423.584961f, 424.804504f, 426.024139f, 427.245911f, 428.467682f, 429.687317f, 430.906921f, 432.128662f, 433.350464f, 434.570068f, 435.789703f, 437.011505f, 438.233276f, 439.452911f, 440.672577f, 441.894348f, 443.116119f, 444.335724f, 445.555359f, 446.777130f, 447.998901f, 449.218567f, 450.438202f, 451.659943f, 452.881714f, 454.101318f, 455.320984f, 456.542725f, 457.764526f, 458.984131f, 460.203857f, 461.425568f, 462.647308f, 463.866882f, 465.086609f, 466.308319f, 467.530029f, 468.749756f, 469.969452f, 471.191162f, 472.412903f, 473.632568f, 474.852264f, 476.073975f, 477.295746f, 478.515411f, 479.735107f, 480.956787f, 482.178528f, 483.398193f, 484.617859f, 485.839600f, 487.061340f, 488.281036f, 489.500732f, 490.722412f, 491.944153f, 493.163818f, 494.383484f, 495.605225f, 496.826965f, 498.046661f, 499.266357f, 500.488037f, 501.709778f, 502.929382f, 504.149109f, 505.370819f, 506.592468f, 507.812195f, 509.031891f, 510.253540f, 511.475281f, 512.694946f, 513.914673f, 515.136353f, 516.358032f, 517.577820f, 518.797546f, 520.019165f, 521.240906f, 522.460571f, 523.680298f, 524.902039f, 526.123657f, 527.343445f, 528.563171f, 529.784790f, 531.006470f, 532.226196f, 533.445923f, 534.667603f, 535.889282f, 537.109009f, 538.328735f, 539.550415f, 540.772095f, 541.991760f, 543.211548f, 544.433228f, 545.654907f, 546.874634f, 548.094360f, 549.315979f, 550.537720f, 551.757446f, 552.977173f, 554.198853f, 555.420532f, 556.640259f, 557.859985f, 559.081665f, 560.303345f, 561.523010f, 562.742798f, 563.964417f, 565.186096f, 566.405884f, 567.625610f, 568.847229f, 570.068909f, 571.288696f, 572.508423f, 573.730042f, 574.951721f, 576.171509f, 577.391235f, 578.612854f, 579.834534f, 581.054260f, 582.273987f, 583.495667f, 584.717346f, 585.937073f, 587.156799f, 588.378418f, 589.600098f, 590.819824f, 592.039551f, 593.261230f, 594.482910f, 595.702637f, 596.922424f, 598.144043f, 599.365723f, 600.585449f, 601.805176f, 603.026855f, 604.248535f, 605.468323f, 606.688049f, 607.909668f, 609.131348f, 610.351074f, 611.570801f, 612.792480f, 614.014160f, 615.233948f, 616.453674f, 617.675293f, 618.896973f, 620.116699f, 621.336487f, 622.558105f, 623.779785f, 625.000000f, 626.219727f, 627.441345f, 628.663025f, 629.882751f, 631.102539f, 632.324158f, 633.545837f, 634.765625f, 635.985352f, 637.206970f, 638.428650f, 639.648376f, 640.868164f, 642.089783f, 643.311462f, 644.531250f, 645.750977f, 646.972595f, 648.194275f, 649.414001f, 650.633789f, 651.855408f, 653.077087f, 654.296875f, 655.516602f, 656.738220f, 657.959961f, 659.179688f, 660.399414f, 661.621033f, 662.842712f, 664.062500f, 665.282227f, 666.503845f, 667.725464f, 668.945251f, 670.164978f, 671.386658f, 672.608276f, 673.828064f, 675.047852f, 676.269409f, 677.491150f, 678.710815f, 679.930603f, 681.152222f, 682.373962f, 683.593750f, 684.813477f, 686.035095f, 687.256775f, 688.476501f, 689.696228f, 690.917908f, 692.139587f, 693.359314f, 694.579041f, 695.800720f, 697.022400f, 698.242126f, 699.461853f, 700.683533f, 701.905151f, 703.124939f, 704.344666f, 705.566284f, 706.788025f, 708.007751f, 709.227417f, 710.449097f, 711.670837f, 712.890564f, 714.110291f, 715.331909f, 716.553650f, 717.773315f, 718.993042f, 720.214722f, 721.436401f, 722.656189f, 723.875916f, 725.097534f, 726.319214f, 727.538940f, 728.758667f, 729.980347f, 731.202026f, 732.421753f, 733.641479f, 734.863159f, 736.084839f, 737.304565f, 738.524292f, 739.745972f, 740.967651f, 742.187378f, 743.407043f, 744.628723f, 745.850403f, 747.070129f, 748.289795f, 749.511536f, 750.733215f, 751.952942f, 753.172668f, 754.394287f, 755.616028f, 756.835693f, 758.055420f, 759.277100f, 760.498901f, 761.718628f, 762.938232f, 764.159912f, 765.381653f, 766.601318f, 767.821045f, 769.042725f, 770.264465f, 771.484192f, 772.703857f, 773.925537f, 775.147278f, 776.366943f, 777.586670f, 778.808350f, 780.030090f, 781.249878f, 782.469543f, 783.691223f, 784.912964f, 786.132690f, 787.352295f, 788.574036f, 789.795776f, 791.015503f, 792.235107f, 793.456848f, 794.678589f, 795.898254f, 797.117920f, 798.339661f, 799.561401f, 800.781128f, 802.000671f, 803.222412f, 804.444214f, 805.663818f, 806.883484f, 808.105225f, 809.327026f, 810.546753f, 811.766296f, 812.988037f, 814.209839f, 815.429504f, 816.649109f, 817.870850f, 819.092712f, 820.312317f, 821.531860f, 822.753662f, 823.975464f, 825.195068f, 826.414673f, 827.636475f, 828.858215f, 830.077881f, 831.297485f, 832.519287f, 833.741089f, 834.960693f, 836.180298f, 837.402100f, 838.623901f, 839.843628f, 841.063110f, 842.284912f, 843.506714f, 844.726318f, 845.945862f, 847.167725f, 848.389526f, 849.609131f, 850.828674f, 852.050537f, 853.272339f, 854.491943f, 855.711487f, 856.933350f, 858.155151f, 859.374817f, 860.594299f, 861.816101f, 863.037964f, 864.257568f, 865.477051f, 866.698914f, 867.920776f, 869.140381f, 870.359863f, 871.581787f, 872.803650f, 874.023193f, 875.242676f, 876.464539f, 877.686462f, 878.906006f, 880.125488f, 881.347351f, 882.569214f, 883.788757f, 885.008301f, 886.230103f, 887.452087f, 888.671631f, 889.891052f, 891.112976f, 892.334900f, 893.554443f, 894.773865f, 895.995789f, 897.217773f, 898.437256f, 899.656738f, 900.878601f, 902.100525f, 903.320007f, 904.539429f, 905.761353f, 906.983276f, 908.202820f, 909.422241f, 910.644165f, 911.866211f, 913.085571f, 914.305054f, 915.526978f, 916.749023f, 917.968506f, 919.187805f, 920.409790f, 921.631836f, 922.851196f, 924.070557f, 925.292603f, 926.514648f, 927.734070f, 928.953369f, 930.175415f, 931.397461f, 932.616882f, 933.836182f, 935.058228f, 936.280273f, 937.499878f, 938.719238f, 939.941223f, 941.163330f, 942.382690f, 943.601990f, 944.824036f, 946.046082f, 947.265503f, 948.484741f, 949.706848f, 950.928955f, 952.148254f, 953.367554f, 954.589661f, 955.811768f, 957.031128f, 958.250366f, 959.472412f, 960.694580f, 961.913818f, 963.133118f, 964.355225f, 965.577393f, 966.796753f, 968.015869f, 969.238037f, 970.460327f, 971.679565f, 972.898804f, 974.120911f, 975.343140f, 976.562378f, 977.781494f, 979.003662f, 980.225952f, 981.445129f, 982.664246f, 983.886475f, 985.108643f, 986.327881f, 987.546997f, 988.769287f, 989.991577f, 991.210693f, 992.429810f, 993.652100f, 994.874451f, 996.093628f, 997.312622f, 998.534912f, 999.757202f, 1000.976318f, 1002.195313f, 1003.417725f, 1004.640137f, 1005.859192f, 1007.078125f, 1008.300537f, 1009.522949f, 1010.741943f, 1011.960938f, 1013.183350f, 1014.405762f, 1015.624878f, 1016.843750f, 1018.066162f, 1019.288635f, 1020.507629f, 1021.726563f, 1022.948975f, 1024.171387f, 1025.390381f, 1026.609375f, 1027.831787f, 1029.054443f, 1030.273193f, 1031.492065f, 1032.714600f, 1033.937256f, 1035.156128f, 1036.374878f, 1037.597412f, 1038.819946f, 1040.038818f, 1041.257568f, 1042.480225f, 1043.702759f, 1044.921631f, 1046.140381f, 1047.363037f, 1048.585693f, 1049.804443f, 1051.023193f, 1052.245850f, 1053.468628f, 1054.687256f, 1055.905884f, 1057.128662f, 1058.351318f, 1059.570068f, 1060.788574f, 1062.011475f, 1063.234253f, 1064.452881f, 1065.671387f, 1066.894287f, 1068.117188f, 1069.335693f, 1070.554199f, 1071.776978f, 1073.000000f, 1074.218506f, 1075.436890f, 1076.659790f, 1077.882813f, 1079.101318f, 1080.319702f, 1081.542725f, 1082.765747f, 1083.984131f, 1085.202393f, 1086.425537f, 1087.648560f, 1088.866943f, 1090.085205f, 1091.308350f, 1092.531494f, 1093.749878f, 1094.968018f, 1096.191162f, 1097.414429f, 1098.632568f, 1099.850708f, 1101.073975f, 1102.297363f, 1103.515381f, 1104.733398f, 1105.956787f, 1107.180176f, 1108.398193f, 1109.616089f, 1110.839600f, 1112.063232f, 1113.281006f, 1114.498779f, 1115.722412f, 1116.946045f, 1118.163818f, 1119.381592f, 1120.605225f, 1121.828979f, 1123.046631f, 1124.264160f, 1125.488037f, 1126.711914f, 1127.929565f, 1129.146973f, 1130.370972f, 1131.594971f, 1132.812500f, 1134.029785f, 1135.253784f, 1136.477905f, 1137.695068f, 1138.912354f, 1140.136597f, 1141.360840f, 1142.577881f, 1143.795044f, 1145.019409f, 1146.243896f, 1147.460693f, 1148.677734f, 1149.902222f, 1151.126831f, 1152.343628f, 1153.560181f, 1154.784912f, 1156.009766f, 1157.226318f, 1158.442871f, 1159.667847f, 1160.892822f, 1162.109131f, 1163.325439f, 1164.550659f, 1165.775879f, 1166.991943f, 1168.208008f, 1169.433594f, 1170.659058f, 1171.874878f, 1173.090576f, 1174.316284f, 1175.542114f, 1176.757568f, 1177.973022f, 1179.199219f, 1180.425293f, 1181.640381f, 1182.855469f, 1184.081909f, 1185.308472f, 1186.523193f, 1187.737793f, 1188.964844f, 1190.191895f, 1191.406006f, 1192.620117f, 1193.847656f, 1195.075195f, 1196.288696f, 1197.502197f, 1198.730469f, 1199.958618f, 1201.171509f, 1202.384277f, 1203.613281f, 1204.842285f, 1206.054199f, 1207.266235f, 1208.496338f, 1209.726196f, 1210.937012f, 1212.147949f, 1213.379272f, 1214.610352f, 1215.819824f, 1217.029297f, 1218.262207f, 1219.494873f, 1220.702271f, 1221.910034f, 1223.145142f, 1224.379883f, 1225.584961f, 1226.790039f, 1228.028320f, 1229.266357f, 1230.467041f, 1231.668457f, 1232.911865f, 1234.154541f, 1235.348633f, 1236.543945f, 1237.796631f, 1239.047485f, 1240.228394f, 1241.411865f, 1242.685547f, 1243.954346f, 1245.096924f, 1246.250122f, 1247.616211f, 1248.934570f, 1249.505371f, 1248.934814f, 1247.616333f, 1246.250244f, 1245.096924f, 1243.954590f, 1242.685791f, 1241.411987f, 1240.228638f, 1239.047607f, 1237.796875f, 1236.544189f, 1235.348877f, 1234.154785f, 1232.912109f, 1231.668701f, 1230.467285f, 1229.266357f, 1228.028564f, 1226.790161f, 1225.584961f, 1224.380127f, 1223.145264f, 1221.910156f, 1220.702393f, 1219.494873f, 1218.262207f, 1217.029419f, 1215.819824f, 1214.610474f, 1213.379395f, 1212.148193f, 1210.937256f, 1209.726318f, 1208.496338f, 1207.266357f, 1206.054443f, 1204.842529f, 1203.613525f, 1202.384399f, 1201.171631f, 1199.958740f, 1198.730713f, 1197.502441f, 1196.288818f, 1195.075317f, 1193.847900f, 1192.620239f, 1191.406128f, 1190.191895f, 1188.964844f, 1187.737793f, 1186.523193f, 1185.308594f, 1184.082153f, 1182.855713f, 1181.640625f, 1180.425293f, 1179.199219f, 1177.973145f, 1176.757813f, 1175.542236f, 1174.316528f, 1173.090820f, 1171.875000f, 1170.659180f, 1169.433838f, 1168.208252f, 1166.992188f, 1165.776123f, 1164.550903f, 1163.325562f, 1162.109375f, 1160.893066f, 1159.668091f, 1158.443115f, 1157.226563f, 1156.010010f, 1154.785278f, 1153.560547f, 1152.343750f, 1151.126953f, 1149.902344f, 1148.677734f, 1147.460938f, 1146.244141f, 1145.019653f, 1143.795166f, 1142.578125f, 1141.361084f, 1140.136841f, 1138.912598f, 1137.695313f, 1136.478149f, 1135.254028f, 1134.030029f, 1132.812622f, 1131.595215f, 1130.371338f, 1129.147217f, 1127.929810f, 1126.712280f, 1125.488403f, 1124.264526f, 1123.046997f, 1121.829346f, 1120.605469f, 1119.381836f, 1118.164063f, 1116.946411f, 1115.722778f, 1114.499146f, 1113.281250f, 1112.063477f, 1110.839966f, 1109.616455f, 1108.398438f, 1107.180542f, 1105.957153f, 1104.733643f, 1103.515625f, 1102.297485f, 1101.074219f, 1099.850952f, 1098.632935f, 1097.414673f, 1096.191406f, 1094.968262f, 1093.750122f, 1092.531860f, 1091.308716f, 1090.085449f, 1088.867310f, 1087.648926f, 1086.425903f, 1085.202637f, 1083.984375f, 1082.766113f, 1081.543091f, 1080.319946f, 1079.101563f, 1077.883179f, 1076.660156f, 1075.437256f, 1074.218750f, 1073.000244f, 1071.777344f, 1070.554443f, 1069.335938f, 1068.117432f, 1066.894531f, 1065.671753f, 1064.453125f, 1063.234619f, 1062.011719f, 1060.788940f, 1059.570435f, 1058.351807f, 1057.129028f, 1055.906250f, 1054.687622f, 1053.468994f, 1052.246216f, 1051.023438f, 1049.804810f, 1048.586182f, 1047.363403f, 1046.140747f, 1044.921997f, 1043.703125f, 1042.480591f, 1041.257935f, 1040.039185f, 1038.820313f, 1037.597778f, 1036.375244f, 1035.156372f, 1033.937500f, 1032.714966f, 1031.492432f, 1030.273560f, 1029.054688f, 1027.832275f, 1026.609619f, 1025.390747f, 1024.171875f, 1022.949341f, 1021.726868f, 1020.507996f, 1019.289001f, 1018.066528f, 1016.844116f, 1015.625122f, 1014.406128f, 1013.183716f, 1011.961304f, 1010.742310f, 1009.523315f, 1008.300903f, 1007.078491f, 1005.859497f, 1004.640503f, 1003.418091f, 1002.195740f, 1000.976746f, 999.757690f, 998.535278f, 997.312988f, 996.093872f, 994.874756f, 993.652466f, 992.430176f, 991.211060f, 989.991943f, 988.769653f, 987.547363f, 986.328247f, 985.109009f, 983.886841f, 982.664551f, 981.445496f, 980.226257f, 979.004089f, 977.781860f, 976.562744f, 975.343506f, 974.121338f, 972.899048f, 971.679932f, 970.460693f, 969.238403f, 968.016235f, 966.797058f, 965.577820f, 964.355591f, 963.133423f, 961.914246f, 960.695007f, 959.472778f, 958.250732f, 957.031433f, 955.812134f, 954.589966f, 953.367920f, 952.148621f, 950.929321f, 949.707275f, 948.485046f, 947.265747f, 946.046387f, 944.824341f, 943.602295f, 942.382996f, 941.163696f, 939.941589f, 938.719543f, 937.500061f, 936.280640f, 935.058655f, 933.836548f, 932.617188f, 931.397827f, 930.175842f, 928.953735f, 927.734375f, 926.515015f, 925.292969f, 924.070984f, 922.851563f, 921.632202f, 920.410156f, 919.188171f, 917.968750f, 916.749329f, 915.527344f, 914.305420f, 913.085938f, 911.866577f, 910.644531f, 909.422607f, 908.203125f, 906.983643f, 905.761780f, 904.539795f, 903.320435f, 902.100952f, 900.878967f, 899.657043f, 898.437561f, 897.218140f, 895.996216f, 894.774292f, 893.554810f, 892.335327f, 891.113281f, 889.891357f, 888.671936f, 887.452393f, 886.230530f, 885.008606f, 883.789185f, 882.569641f, 881.347717f, 880.125854f, 878.906311f, 877.686768f, 876.464905f, 875.242981f, 874.023499f, 872.803955f, 871.582153f, 870.360229f, 869.140747f, 867.921143f, 866.699280f, 865.477417f, 864.257935f, 863.038391f, 861.816528f, 860.594727f, 859.375122f, 858.155518f, 856.933716f, 855.711914f, 854.492310f, 853.272766f, 852.050903f, 850.829041f, 849.609497f, 848.389954f, 847.168152f, 845.946289f, 844.726746f, 843.507141f, 842.285278f, 841.063477f, 839.843872f, 838.624268f, 837.402466f, 836.180664f, 834.961060f, 833.741516f, 832.519653f, 831.297852f, 830.078247f, 828.858643f, 827.636841f, 826.415039f, 825.195496f, 823.975830f, 822.754089f, 821.532349f, 820.312683f, 819.093079f, 817.871338f, 816.649536f, 815.429932f, 814.210327f, 812.988525f, 811.766724f, 810.547119f, 809.327393f, 808.105652f, 806.883911f, 805.664307f, 804.444641f, 803.222900f, 802.001099f, 800.781433f, 799.561768f, 798.340088f, 797.118286f, 795.898682f, 794.679016f, 793.457275f, 792.235474f, 791.015869f, 789.796143f, 788.574463f, 787.352661f, 786.133118f, 784.913391f, 783.691650f, 782.469971f, 781.250244f, 780.030518f, 778.808838f, 777.587097f, 776.367432f, 775.147705f, 773.926025f, 772.704224f, 771.484619f, 770.264893f, 769.043213f, 767.821472f, 766.601807f, 765.382141f, 764.160400f, 762.938660f, 761.718994f, 760.499268f, 759.277588f, 758.055847f, 756.836182f, 755.616516f, 754.394775f, 753.173035f, 751.953369f, 750.733643f, 749.511963f, 748.290222f, 747.070618f, 745.850891f, 744.629211f, 743.407532f, 742.187805f, 740.968140f, 739.746460f, 738.524719f, 737.305054f, 736.085327f, 734.863647f, 733.641968f, 732.422180f, 731.202454f, 729.980835f, 728.759094f, 727.539429f, 726.319702f, 725.097961f, 723.876343f, 722.656555f, 721.436829f, 720.215210f, 718.993530f, 717.773804f, 716.554077f, 715.332397f, 714.110718f, 712.890991f, 711.671265f, 710.449585f, 709.227905f, 708.008240f, 706.788452f, 705.566772f, 704.345093f, 703.125366f, 701.905640f, 700.684021f, 699.462280f, 698.242554f, 697.022827f, 695.801147f, 694.579468f, 693.359741f, 692.140015f, 690.918335f, 689.696655f, 688.476990f, 687.257202f, 686.035583f, 684.813904f, 683.594116f, 682.374390f, 681.152771f, 679.931091f, 678.711304f, 677.491577f, 676.269958f, 675.048279f, 673.828491f, 672.608765f, 671.387146f, 670.165466f, 668.945740f, 667.726013f, 666.504333f, 665.282654f, 664.062927f, 662.843201f, 661.621582f, 660.399902f, 659.180176f, 657.960449f, 656.738770f, 655.517090f, 654.297363f, 653.077576f, 651.855957f, 650.634277f, 649.414551f, 648.194824f, 646.973145f, 645.751465f, 644.531677f, 643.311951f, 642.090332f, 640.868652f, 639.648926f, 638.429199f, 637.207520f, 635.985840f, 634.766052f, 633.546326f, 632.324707f, 631.103027f, 629.883301f, 628.663513f, 627.441895f, 626.220215f, 625.000000f, 623.780273f, 622.558655f, 621.336975f, 620.117249f, 618.897461f, 617.675842f, 616.454163f, 615.234375f, 614.014648f, 612.793030f, 611.571350f, 610.351624f, 609.131836f, 607.910217f, 606.688538f, 605.468750f, 604.249023f, 603.027405f, 601.805725f, 600.585999f, 599.366211f, 598.144592f, 596.922913f, 595.703125f, 594.483398f, 593.261780f, 592.040039f, 590.820313f, 589.600586f, 588.378967f, 587.157288f, 585.937500f, 584.717773f, 583.496155f, 582.274536f, 581.054749f, 579.835022f, 578.613342f, 577.391724f, 576.171936f, 574.952148f, 573.730591f, 572.508850f, 571.289185f, 570.069397f, 568.847778f, 567.626038f, 566.406250f, 565.186523f, 563.964905f, 562.743225f, 561.523499f, 560.303772f, 559.082092f, 557.860413f, 556.640686f, 555.420959f, 554.199280f, 552.977600f, 551.757874f, 550.538147f, 549.316467f, 548.094849f, 546.875061f, 545.655334f, 544.433716f, 543.211975f, 541.992249f, 540.772583f, 539.550903f, 538.329163f, 537.109436f, 535.889709f, 534.668091f, 533.446350f, 532.226685f, 531.006958f, 529.785278f, 528.563599f, 527.343811f, 526.124084f, 524.902466f, 523.680786f, 522.461060f, 521.241333f, 520.019653f, 518.797974f, 517.578247f, 516.358521f, 515.136841f, 513.915161f, 512.695435f, 511.475739f, 510.254028f, 509.032349f, 507.812622f, 506.592957f, 505.371277f, 504.149597f, 502.929871f, 501.710205f, 500.488464f, 499.266785f, 498.047058f, 496.827332f, 495.605682f, 494.383972f, 493.164307f, 491.944580f, 490.722900f, 489.501129f, 488.281403f, 487.061798f, 485.840088f, 484.618347f, 483.398651f, 482.178955f, 480.957245f, 479.735535f, 478.515808f, 477.296173f, 476.074432f, 474.852722f, 473.633057f, 472.413361f, 471.191620f, 469.969910f, 468.750122f, 467.530457f, 466.308777f, 465.087036f, 463.867340f, 462.647705f, 461.425964f, 460.204224f, 458.984497f, 457.764893f, 456.543152f, 455.321411f, 454.101746f, 452.882111f, 451.660339f, 450.438599f, 449.218903f, 447.999329f, 446.777557f, 445.555786f, 444.336151f, 443.116516f, 441.894745f, 440.672974f, 439.453278f, 438.233704f, 437.011932f, 435.790131f, 434.570496f, 433.350891f, 432.129120f, 430.907288f, 429.687683f, 428.468109f, 427.246338f, 426.024536f, 424.804932f, 423.585327f, 422.363525f, 421.141785f, 419.922089f, 418.702484f, 417.480743f, 416.258911f, 415.039307f, 413.819702f, 412.597900f, 411.376068f, 410.156403f, 408.936890f, 407.715088f, 406.493286f, 405.273682f, 404.054138f, 402.832275f, 401.610474f, 400.390869f, 399.171326f, 397.949493f, 396.727631f, 395.508057f, 394.288513f, 393.066650f, 391.844818f, 390.625183f, 389.405701f, 388.183899f, 386.962006f, 385.742432f, 384.522919f, 383.301086f, 382.079224f, 380.859589f, 379.640106f, 378.418243f, 377.196350f, 375.976837f, 374.757324f, 373.535461f, 372.313538f, 371.093964f, 369.874512f, 368.652649f, 367.430756f, 366.211243f, 364.991730f, 363.769867f, 362.547913f, 361.328369f, 360.108948f, 358.887024f, 357.665100f, 356.445587f, 355.226135f, 354.004211f, 352.782257f, 351.562775f, 350.343292f, 349.121399f, 347.899475f, 346.679993f, 345.460571f, 344.238617f, 343.016693f, 341.797180f, 340.577789f, 339.355835f, 338.133820f, 336.914398f, 335.694977f, 334.473022f, 333.250977f, 332.031525f, 330.812195f, 329.590240f, 328.368195f, 327.148773f, 325.929443f, 324.707367f, 323.485382f, 322.265930f, 321.046631f, 319.824554f, 318.602570f, 317.383118f, 316.163788f, 314.941742f, 313.719696f, 312.500092f, 311.280792f, 310.058777f, 308.836700f, 307.617340f, 306.398010f, 305.175964f, 303.953918f, 302.734497f, 301.515259f, 300.293152f, 299.071045f, 297.851746f, 296.632446f, 295.410339f, 294.188232f, 292.968842f, 291.749664f, 290.527557f, 289.305389f, 288.086151f, 286.866882f, 285.644775f, 284.422577f, 283.203278f, 281.984100f, 280.761932f, 279.539703f, 278.320435f, 277.101227f, 275.879089f, 274.656830f, 273.437622f, 272.218506f, 270.996338f, 269.774078f, 268.554871f, 267.335754f, 266.113525f, 264.891327f, 263.672089f, 262.452972f, 261.230713f, 260.008423f, 258.789307f, 257.570190f, 256.347900f, 255.125549f, 253.906403f, 252.687408f, 251.465088f, 250.242767f, 249.023651f, 247.804657f, 246.582275f, 245.359894f, 244.140808f, 242.921906f, 241.699493f, 240.477081f, 239.258057f, 238.039063f, 236.816650f, 235.594238f, 234.375153f, 233.156219f, 231.933838f, 230.711365f, 229.492371f, 228.273468f, 227.051025f, 225.828552f, 224.609558f, 223.390686f, 222.168182f, 220.945618f, 219.726746f, 218.507904f, 217.285370f, 216.062805f, 214.843903f, 213.625122f, 212.402618f, 211.180023f, 209.961212f, 208.742401f, 207.519806f, 206.297211f, 205.078369f, 203.859619f, 202.636993f, 201.414307f, 200.195496f, 198.976837f, 197.754120f, 196.531403f, 195.312714f, 194.094086f, 192.871368f, 191.648651f, 190.429932f, 189.211365f, 187.988586f, 186.765778f, 185.547150f, 184.328613f, 183.105774f, 181.882874f, 180.664368f, 179.445862f, 178.222992f, 177.000031f, 175.781555f, 174.563141f, 173.340179f, 172.117157f, 170.898743f, 169.680328f, 168.457275f, 167.234283f, 166.015869f, 164.797607f, 163.574493f, 162.351410f, 161.133026f, 159.914856f, 158.691620f, 157.468445f, 156.250153f, 155.032043f, 153.808838f, 152.585571f, 151.367371f, 150.149292f, 148.925964f, 147.702698f, 146.484619f, 145.266602f, 144.043182f, 142.819763f, 141.601776f, 140.383881f, 139.160339f, 137.936829f, 136.718933f, 135.501160f, 134.277588f, 133.053955f, 131.836212f, 130.618439f, 129.394745f, 128.170990f, 126.953339f, 125.735779f, 124.511902f, 123.288055f, 122.070435f, 120.852997f, 119.628998f, 118.404999f, 117.187561f, 115.970276f, 114.746216f, 113.522125f, 112.304871f, 111.087646f, 109.863403f, 108.639160f, 107.422058f, 106.204956f, 104.980591f, 103.756165f, 102.539246f, 101.322327f, 100.097778f, 98.873169f, 97.656372f, 96.439819f, 95.215027f, 93.990234f, 92.773621f, 91.557129f, 90.332153f, 89.107178f, 87.890869f, 86.674622f, 85.449341f, 84.224182f, 83.007996f, 81.791992f, 80.566467f, 79.340942f, 78.125122f, 76.909424f, 75.683716f, 74.457886f, 73.242371f, 72.026978f, 70.800842f, 69.574768f, 68.359558f, 67.144531f, 65.918091f, 64.691528f, 63.476868f, 62.262207f, 61.035156f, 59.808167f, 58.593994f, 57.379944f, 56.152344f, 54.924866f, 53.711304f, 52.497742f, 51.269470f, 50.041382f, 48.828491f, 47.615784f, 46.386658f, 45.157715f, 43.945740f, 42.733765f, 41.503723f, 40.273804f, 39.062927f, 37.851990f, 36.620728f, 35.389709f, 34.180237f, 32.970764f, 31.737793f, 30.505188f, 29.297729f, 28.089966f, 26.854858f, 25.620056f, 24.415100f, 23.209900f, 21.971619f, 20.733704f, 19.532898f, 18.331543f, 17.088135f, 15.845459f, 14.651306f, 13.456055f, 12.203369f, 10.952515f, 9.771606f, 8.588196f, 7.314453f, 6.045593f, 4.903137f, 3.749878f, 2.383789f, 1.065430f
};


static void printGlobalData(GPUComputingTransaction *data_info) {
    float * global_data = (float *)malloc(data_info->local_data_width*4*sizeof(float));
    memset(global_data, 0, data_info->local_data_width*4*sizeof(float));
    ((Buffer *)(data_info->localBufferHandles[0]))->readData(global_data, data_info->local_data_width);
    debug_info(global_data);
}





DataTransManager::DataTransManager(BufferManager *bufMgr, ProgramManager *progMgr) 
{
    _bufMgr = bufMgr;
    _progMgr = progMgr;
    
    _fft_cs_input_ProgInfo = ProgramInfo("CS_INPUT@TomoFFT", fft_cs_input_tomo_fft_source_).isCompute().inputs(2).hasGlobal();
    
    _fft_ps_input_ProgInfo = ProgramInfo("PS_INPUT@TomoFFT", fft_ps_gbuf_input_tomo_fft_source_).inputs(2).hasGlobal();
    //_fft_ps_input_ProgInfo = ProgramInfo("PS_INPUT@TomoFFT", fft_ps_out_input_tomo_fft_source_).inputs(2).outputs(1);

    _fft_ps_ouput_ProgInfo = ProgramInfo("PS_OUTPUT@TomoFFT", _output_2048_512_tomo_fft_source_).inputs(1).outputs(2);
}





bool DataTransManager::transferToGPU_CS(Device *device, float *user_data, const unsigned int width, const unsigned int height) {
    
    Timer timer;
    GPUComputingTransaction *data_info = GPUDataMap[device];
    Program *IN_program = data_info->transferIN_Program;

//data_info->inputBufferNum=1;

    /*PHASE 1,initialize input buffer*/

	const unsigned int orig_data_size = width*height*sizeof(float);
    const unsigned int data_float_size_per_input = (width*height)/data_info->inputBufferNum;
    const unsigned int data_float4_size_per_input = data_float_size_per_input/4;
    const unsigned int buffer_width = INPUT_BUFFER_WIDTH;//data_float4_size_per_input/MAX_REMOTE_BUFFER_LINE_FLOAT4;
    const unsigned int buffer_height = data_float4_size_per_input/INPUT_BUFFER_WIDTH;
    if(buffer_height>MAX_REMOTE_BUFFER_LINE_FLOAT4)
    {
        LOG_ERROR("Input buffer height exceeds the boudary!\n");
        endGPUCompute(device);
        return false;
    }

    const unsigned int batchNum = data_float4_size_per_input/(64*2);        //one block has 64 threads, each threads handles 2 float4s

    float *input_data = user_data;
    for(unsigned int i=0; i<data_info->inputBufferNum;i++) {
      Buffer* inBuffer =
          _bufMgr->createPinnedBuffer(device, CAL_FORMAT_FLOAT_4, buffer_width, buffer_height, input_data);
       if(!inBuffer) {
          LOG_ERROR("Failed to create input buffer!\n");
          endGPUCompute(device);
          return false;
       }
       IN_program->bindInput(inBuffer, i);
       input_data += data_float_size_per_input;
       data_info->inputBufferHandles[i] = inBuffer;
    }


    /*PHASE 2, bind local buffer*/
    if(!data_info->localBufferHandles[0]) {
        LOG_ERROR("the local buffer is not initialized!");
        endGPUCompute(device);
    }

    unsigned int local_float_size = data_info->localBufferHandles[0]->getHeight() * data_info->localBufferHandles[0]->getWidth() * 4;
    const unsigned int computing_data_float_size = (width*height)<<DATA_EXTENSION_SHIFT_BIT;
    if(local_float_size!=computing_data_float_size) {
        LOG_ERROR("the local buffer size is not suitable to input!");
        endGPUCompute(device);
    }

    IN_program->bindGlobal(data_info->localBufferHandles[0]);

    timer.start();
    /*PHASE 3, program run*/
    ComputeProgExeInfo exeInfo(0, uint3(64, 1, 1), uint3(batchNum, 1, 1));
    IN_program->setExeInfo(exeInfo);

    Event *e = IN_program->run();
    if (!e) {
        endGPUCompute(device);
        return false;
    }
    
    e->waitEvent();

    timer.stop();
    printf("input time %fs\n", timer.getElapsedTime());
  

    IN_program->unbindAll();
    data_info->transferIN_Event = e;
    return true;
}






bool DataTransManager::transferToGPU_PS(Device *device, float *user_data, const unsigned int width, const unsigned int height)
{
    Timer timer;
    GPUComputingTransaction *data_info = GPUDataMap[device];

    Program *IN_program = data_info->transferIN_Program;

    /*PHASE 1, initialize input buffer*/

    const unsigned int orig_data_size = width*height*sizeof(float);
    const unsigned int data_float_size_per_input = (width*height)/data_info->inputBufferNum;
    const unsigned int data_float4_size_per_input = data_float_size_per_input/4;
    const unsigned int buffer_width = INPUT_BUFFER_WIDTH;//data_float4_size_per_input/MAX_REMOTE_BUFFER_LINE_FLOAT4;
    const unsigned int buffer_height = data_float4_size_per_input/INPUT_BUFFER_WIDTH;
    if(buffer_height>MAX_REMOTE_BUFFER_LINE_FLOAT4)
    {
        LOG_ERROR("Input buffer height exceeds the boudary!\n");
        endGPUCompute(device);
        return false;
    }
    //const unsigned int batchNum = data_float4_size_per_input/(64*2);        //one block has 64 threads, each threads handles 2 float4s
    
    timer.start();

    float *input_data = user_data;
    for(unsigned int i=0; i<data_info->inputBufferNum;i++) {
      Buffer* inBuffer =
          _bufMgr->createPinnedBuffer(device, CAL_FORMAT_FLOAT_4, buffer_width, buffer_height, input_data);
       if(!inBuffer) {
          LOG_ERROR("Failed to create input buffer!\n");
          endGPUCompute(device);
          return false;
       }
       IN_program->bindInput(inBuffer, i);
       input_data += data_float_size_per_input;
       data_info->inputBufferHandles[i] = inBuffer;
    }

    /*PHASE 2, initialize local buffer*/
    const unsigned int computing_data_float_size = (width*height)<<DATA_EXTENSION_SHIFT_BIT;
    if(MAX_LOCAL_BUFFER_FLOAT_SIZE<computing_data_float_size) {
        LOG_ERROR("the requesting local buffer is too large!");
        endGPUCompute(device);
        return false;
    }

    const unsigned int computing_data_float4_size = computing_data_float_size/4;
    unsigned int local_buffer_width, local_buffer_height;
    if(!(computing_data_float4_size%MAX_LOCAL_BUFFER_LINE_FLOAT4)) {
        local_buffer_width = MAX_LOCAL_BUFFER_LINE_FLOAT4;
    } else {
        LOG_ERROR("the computing data size SHOULD be factor of 8192*16 bytes!");
        endGPUCompute(device);
        return false;
    }
    local_buffer_height = computing_data_float4_size/local_buffer_width;
    data_info->local_data_width = local_buffer_width;
    data_info->local_data_height = local_buffer_height;

     LocalBuffer* gBuf = 
        (LocalBuffer*)_bufMgr->createLocalBuffer(device, CAL_FORMAT_FLOAT_4, local_buffer_width, local_buffer_height, CAL_RESALLOC_GLOBAL_BUFFER);
    if (!gBuf)
    {
        LOG_ERROR("Failed to create global buffer!\n");
        endGPUCompute(device);
        return false;
    }
    data_info->localBufferHandles[0] = gBuf;
    IN_program->bindGlobal(gBuf);

    /*PHASE 3, program run*/
    GeneralProgExeInfo exeInfo(uint4(0, 0, buffer_width, buffer_height));
    IN_program->setExeInfo(exeInfo);

    Event *e = IN_program->run();
    if (!e) {
        endGPUCompute(device);
        return false;
    }
    
    e->waitEvent();

    timer.stop();
    printf("input time %fs\n", timer.getElapsedTime());
    

    IN_program->unbindAll();
    data_info->transferIN_Event = e;
    return true;
}



ConstBuffer *DataTransManager::getGPUConstBuffer(Device *device)
{
    GPUComputingTransaction *data_info = GPUDataMap[device];
    return data_info->constBufferHandle;
}



LocalBuffer *DataTransManager::getGPUGlobalDataBuffer(Device *device)
{
    GPUComputingTransaction *data_info = GPUDataMap[device];
    //data_info->transferIN_Event->waitEvent();
    return data_info->localBufferHandles[0];
}



bool DataTransManager::transferFromGPU_CS(Device *device, float *userMem)
{
    return true;
}

bool DataTransManager::transferFromGPU_PS(Device *device, float *userMem)
{
    Timer timer;
    GPUComputingTransaction *data_info = GPUDataMap[device];
    Program *OUT_Program = data_info->transferOUT_Program;

    /*PHASE 2, initialize and bind ouput buffer*/
    float *output_mem = userMem;
    Buffer *ouputBuf = NULL;
    const unsigned int output_width = data_info->local_data_width/(2*data_info->outputBufferNum);
    const unsigned int output_height = data_info->local_data_height;
    const unsigned int float_size_per_output = output_width * output_height;
    for(unsigned int i=0;i<data_info->outputBufferNum;i++) {
        ouputBuf = 
            _bufMgr->createPinnedBuffer(device, CAL_FORMAT_FLOAT32_1, output_width, output_height, output_mem);
        if(!ouputBuf)
        {
            printf("calResCreate2D failed when writing back\n");
            return false;
        }
        OUT_Program->bindOutput(ouputBuf, i);
        data_info->outputBufferHandles[i] = ouputBuf;
        output_mem += float_size_per_output;
    }
    
      /*PHASE 3, bind input buffer*/
     OUT_Program->bindInput(data_info->localBufferHandles[0], 0);

     /*PHASE 4, run program*/
     GeneralProgExeInfo exeInfo(uint4(0, 0, output_width, (output_height ? output_height : 1)));
     OUT_Program->setExeInfo(exeInfo);

     timer.start();
     Event *e = OUT_Program->run();
     if (!e) {
        endGPUCompute(device);
        return false;
     }
     e->waitEvent();
     
     timer.stop();
     printf("output Time: %lf\n", timer.getElapsedTime());
     data_info->transferOUT_Event = e;

     OUT_Program->unbindAll();
     destroy_input_buffer(data_info);
     destroy_output_buffer(data_info);
     return true;
}





bool DataTransManager::beginGPUCompute(Device *device)
{
    GPUComputingTransaction *data_info = new GPUComputingTransaction();
    memset(data_info, 0, sizeof(GPUComputingTransaction));

    data_info->localBufferNum = 1; //HARD CODE
    data_info->localBufferHandles = (LocalBuffer **)malloc(data_info->localBufferNum*sizeof(LocalBuffer *));
    memset(data_info->localBufferHandles, 0, data_info->localBufferNum*sizeof(LocalBuffer *));
    
    data_info->outputBufferNum = 2; //HARD CODE!
    data_info->outputBufferHandles = (Buffer **)malloc(data_info->outputBufferNum*sizeof(Buffer *));
    memset(data_info->outputBufferHandles, 0, data_info->outputBufferNum*sizeof(Buffer *));

    data_info->inputBufferNum = 2; //HARD CODE!
    data_info->inputBufferHandles = (Buffer **)malloc(data_info->inputBufferNum*sizeof(Buffer *));
    memset(data_info->inputBufferHandles, 0, data_info->inputBufferNum*sizeof(Buffer *));

    //init output program
    Program *op = _progMgr->loadProgram(_fft_ps_ouput_ProgInfo, device);
    if (!op) {
        endGPUCompute(device);
        return false;
    }
    data_info->transferOUT_Program = op;

    
    /*
    Program *ip_ps = _progMgr->loadProgram(_fft_ps_input_ProgInfo, device);
    if (!ip_ps) {
        endGPUCompute(device);
        return false;
    }
    data_info->transferIN_Program = ip_ps;
    */

    Program *ip_cs = _progMgr->loadProgram(_fft_cs_input_ProgInfo, device);
    if (!ip_cs) {
        endGPUCompute(device);
        return false;
    }
    data_info->transferIN_Program = ip_cs;

    GPUDataMap[device] = data_info;
    return true;
}





bool DataTransManager::initGPUMemory(Device *device, const unsigned int width, const unsigned int height) {

    GPUComputingTransaction *data_info = GPUDataMap[device];

    const unsigned int computing_data_float_size = (width*height)<<DATA_EXTENSION_SHIFT_BIT;
    if(MAX_LOCAL_BUFFER_FLOAT_SIZE<computing_data_float_size) {
        LOG_ERROR("the requesting local buffer is too large!");
        endGPUCompute(device);
        return false;
    }

    const unsigned int computing_data_float4_size = computing_data_float_size/4;
    unsigned int local_buffer_width, local_buffer_height;
    if(!(computing_data_float4_size%MAX_LOCAL_BUFFER_LINE_FLOAT4)) {
        local_buffer_width = MAX_LOCAL_BUFFER_LINE_FLOAT4;
    } else {
        LOG_ERROR("the computing data size SHOULD be factor of 8192*16 bytes!");
        endGPUCompute(device);
        return false;
    }
    local_buffer_height = computing_data_float4_size/local_buffer_width;
    data_info->local_data_width = local_buffer_width;
    data_info->local_data_height = local_buffer_height;

    for(unsigned int i=0; i<data_info->localBufferNum;i++)
    {
        LocalBuffer* localBuf = 
            (LocalBuffer*)_bufMgr->createLocalBuffer(device, CAL_FORMAT_FLOAT_4, local_buffer_width, local_buffer_height, CAL_RESALLOC_GLOBAL_BUFFER);
        if (!localBuf)
        {
            LOG_ERROR("Failed to create global buffer!\n");
            endGPUCompute(device);
            return false;
        }
        data_info->localBufferHandles[i] = localBuf;
    }

    
    ConstBuffer *conBuf = _bufMgr->getConstBuffer(2048);
    amdspl::float4 filter_element;
    unsigned int src_index = 0;
    unsigned int dst_index = 0;
    float tg_value;
    for(unsigned int i=0; i<4; i++) {
        for(unsigned int j=0; j<512; j++) {
            src_index = i + j*4;
            dst_index = i*512 + j;
            tg_value = fft_filter_2048[src_index];
            filter_element.x = tg_value;
            filter_element.y = tg_value;
            filter_element.z = tg_value;
            filter_element.w = tg_value;
            conBuf->setConstant(dst_index, &filter_element);
        }
    }

    data_info->constBufferHandle = conBuf;
    
    return true;
}





bool DataTransManager::endGPUCompute(Device *device)
{
    GPUComputingTransaction *data_info = GPUDataMap[device];
    
    if(data_info->transferIN_Program)
        _progMgr->unloadProgram(data_info->transferIN_Program);
    
    if(data_info) {
        if(data_info->transferOUT_Event)
            data_info->transferOUT_Event->waitEvent();
        if(data_info->transferOUT_Program)
            _progMgr->unloadProgram(data_info->transferOUT_Program);
        GPUDataMap[device] = NULL;
        destroy(data_info);
    } else {
        return false;
    }
    return true;
}
